<?php

/**
 * @author 
 * @copyright 2008
 */
include("settings.php");
//TODO: per page navigation vars
$from = 0; $per_page = 20;
if(isset($_REQUEST['from']) and intval($_REQUEST['from']) != 0)
{
	$from = intval($_REQUEST['from']);
}
if(isset($_REQUEST['per_page']) and intval($_REQUEST['per_page']) != 0)
{
	$per_page = intval($_REQUEST['per_page']);
}
$lim_from = $from * $per_page;
//TODO: $obj_id
$obj_id = 0;
if(isset($_REQUEST['obj_id']) and intval($_REQUEST['obj_id']) != 0)
{
	$obj_id = intval($_REQUEST['obj_id']);
}
//TODO: $do
$do = '';
if(isset($_REQUEST['do']) and strval($_REQUEST['do']) != '')
{
	$do = strval($_REQUEST['do']);
	unset($_REQUEST['do']);
}
//TODO: Doing Item
if(file_exists(ADMIN_DIR.MOD_DIR.$this->dir.'/item.'.$do.MOD_EXT))
{
	include_once(ADMIN_DIR.MOD_DIR.$this->dir.'/item.'.$do.MOD_EXT);
}
//TODO: Items
$items_list=$obj->db->fetch_list("SELECT $obj->id FROM $obj->table ORDER BY login LIMIT $lim_from, $per_page");
if(!empty($items_list))
{
	$items = $obj->getFullInfoByList($items_list);
	if($items != false) $smarty->assign("items",$items);
}

//TODO: Item
if($obj_id != 0)
{
	$item = $obj->getFullInfoById($obj_id);
	if($item != false)
	{
		$smarty->assign("item",$item);
		$do = 'edit';
	}
	else
	{
		$_SESSION['message'] = "Выбранного объекта нет в базе данных.";
		$do = 'none';
	}
}
elseif(isset($_SESSION['try_to_edit_item']))
{
	$smarty->assign("item",$_SESSION['try_to_edit_item']);
	unset($_SESSION['try_to_edit_item']);
	$do = 'edit';
}
elseif(isset($_SESSION['try_to_add_item']))
{
	$smarty->assign("item",$_SESSION['try_to_add_item']);
	unset($_SESSION['try_to_add_item']);
	$do = 'add';
}
else
{
	$do = 'add';
}
//TODO: System messages
if(isset($_SESSION['message']) and strval($_SESSION['message']) != '')
{
	$smarty->assign("message",strval($_SESSION['message']));
	unset($_SESSION['message']);
}
//TODO: Local Error messages
if(isset($_SESSION['error_message']) and !empty($_SESSION['error_message']))
{
	$smarty->assign("error_message",$_SESSION['error_message']);
	unset($_SESSION['error_message']);
}
//TODO: Local Success messages
if(isset($_SESSION['success_message']) and !empty($_SESSION['success_message']))
{
	$smarty->assign("success_message",strval($_SESSION['success_message']));
	unset($_SESSION['success_message']);
}
//TODO: Адресная строка
$this->adress_string = array();
$this->adress_string[] = array(
	'title' =>$this->info['title'],
	'menu_title' =>$this->info['menu_title'],
	'alias' => ADMIN_URL.'/'.$this->full_alias
);
if($obj_id != 0)
{
	$this->adress_string[] = array(
		'title' =>$item['login'],
		'menu_title' =>$item['login'],
		'alias' => ADMIN_URL.'/'.$this->full_alias."?obj_id=".intval($item[$obj->id])
	);
}
//TODO: $smarty->assign
$smarty->assign("do",$do);
$smarty->assign("obj_id",$obj_id);
?>